<?php
/**
 * Model class link to table profiles in database
 *
 * @author Dat Nguyen <datn@evolable.asia>
 */
class Profile extends AppModel {
	var $name = 'Profile';
	var $useTable = 'profiles';
	var $primaryKey = 'id';
	
	var $validate = array(
		'first_name' => array(
			'maxlength' => array(
				'rule' => array('maxLength',45),
				'message' => Messages::firstname_max_length_must_be_less_than_45_characters,
			),
			'minlength' => array(
				'rule' => 'notEmpty',
				'required' => true,
				'message' => Messages::you_must_enter_your_first_name,
			),
			'specialCharacters' => array(
				'rule' => 'specialCharacters',
				'message' => Messages::username_must_contain_only_letters_and_numbers
			)
		),
		'last_name' => array(
			'maxlength' => array(
				'rule' => array('maxLength',45),
				'message' => Messages::lastname_must_be_less_than_45_characters,
			),
			'specialCharacters' => array(
				'rule' => 'specialCharacters',
				'message' => Messages::username_must_contain_only_letters_and_numbers
			)
		),
		'headline' => array(
			'minlength' => array(
				'rule' => array('minLength', 1),
				'required' => true,
				'allowEmpty' => false,
				'message' => Messages::you_must_enter_your_headline,
			),
			'maxlength' => array(
				'rule' => array('maxLength',30),
				'message' => Messages::headline_max_length_must_be_less_than_45_characters,
			),
		
		)
	);
	
	function getProFileByUserId($userId) {
		return $this->find('first', array(
			'conditions' => array(
				$this->alias . '.user_id' => $userId
			)
		));
	}
}